<!DOCTYPE html>
<html>
<head>
	{include file="common_header" /}
	{include file="common_top" /}
</head>
<body>

  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-header">添加用户</div>
      <div class="layui-card-body" style="padding: 15px;">
        <form class="layui-form" action="" lay-filter="component-form-group">

		  
		  <div class="layui-form-item">
            <label class="layui-form-label">用户手机号</label>
            <div class="layui-input-block">
              <input type="text" name="phone" id="phone"   placeholder="用户手机号" class="layui-input">
            </div>
          </div>
		  
		  <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
              <input type="password" name="password" id="password"   placeholder="密码" class="layui-input">
            </div>
          </div>
		  
		  <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-block">
              <input type="password" name="endpassword" id="endpassword"   placeholder="确认密码" class="layui-input">
            </div>
          </div>
		  

          <div class="layui-form-item">
            <label class="layui-form-label">用户状态</label>
            <div class="layui-input-block">
              <input type="radio" name="status" value="1" title="启用" checked="">
              <input type="radio" name="status" value="2" title="禁用">
            </div>
          </div>       
          <div class="layui-form-item layui-layout-admin">
            <div class="layui-input-block">
              <div class="layui-footer" style="left: 0;">
                <div class="layui-btn sub">立即提交</div>
                <button type="reset" class="layui-btn layui-btn-primary ">重置</button>
              </div>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
{include file="common_footer" /} 
<script>
$(".sub").click(function(){
	//if(!$(".btn").hasClass("sub")){return false;}
	var phone        = $("#phone").val();
	var password      = $("#password").val();
	var endpassword = $("#endpassword").val();
	var status       = $("input[name='status']:checked").val();

	if(phone == ""){
		show_error("用户手机号不能为空");
		return false
	}

	if(phone.length < 11 || phone.length > 11){
		show_error("用户手机号格式错误，请重新输入！");
		return false
	}
	
	if(password == ""){
		show_error("密码不能为空");
		return false
	}
	
	if(endpassword == ""){
		show_error("确认密码不能为空");
		return false
	}
	
	if(endpassword != password){
		show_error("二次输入密码不一至，请重新输入！");
		return false
	}

	

	$.ajax({
		type:"POST",
		url:"{:url('users/add')}",
		dataType:"json",
		data:{
			phone:phone,
			password:password,
			status:status,
		},
		success:function(res){
			if(res.status == "success"){
				show_toast_callurl(res.data,"{:url('users/index')}","success");
			}else{
				show_error(res.data);
			}
		},
		error:function(jqXHR){
			console.log("Error: "+jqXHR.status);
		},
	});
	
});
</script>
</body>
</html>
